<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                template="#{webContext.skin0Culomns}"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core">

    <ui:define name="center">
        <h:form id="addUserForm">
            <p:breadCrumb>  
                <p:menuitem value="#{ml.tr('Home')}" url="#{webContext.baseUrl}" />  
                <p:menuitem value="#{ml.tr('User list')}" url="#" />  
            </p:breadCrumb>
            <p:toolbar>
                <p:toolbarGroup align="left">

                    <p:commandButton type="submit"
                                     value="#{ml.tr('Add')}"
                                     image="ui-icon-plus"
                                     actionListener="#{man.redirect(lm.ml('secure/user/add.xhtml'))}"/>

                    <p:commandButton type="submit"
                                     value="#{ml.tr('Show')}"
                                     image="ui-icon-search"
                                     actionListener="#{man.redirect(lm.ml('secure/user/show.xhtml?idUser=',
                                                       secureUserList.user.idUser))}"/>

                    <p:commandButton type="submit"
                                     value="#{ml.tr('Edit')}"
                                     image="ui-icon-pencil"
                                     actionListener="#{man.redirect(lm.ml('secure/user/edit.xhtml?idUser=',
                                                       secureUserList.user.idUser))}"/>

                    <p:commandButton type="button"
                                     onclick="confirmationDelete.show()"
                                     update="display"
                                     image="ui-icon ui-icon-circle-close"
                                     value="#{ml.tr('Delete')}"/>

                    <p:confirmDialog message="#{ml.tr('Are you sure?')}"  
                                     header="#{ml.tr('Deleting user')}" 
                                     severity="alert" widgetVar="confirmationDelete">  
                        <p:commandButton value="#{ml.tr('Yes')}" 
                                         update="addUserForm" 
                                         oncomplete="confirmationDelete.hide()"  
                                         actionListener="#{secureUserList.remove}"/>  
                        <p:commandButton value="#{ml.tr('No')}" 
                                         onclick="confirmationDelete.hide()" 
                                         type="button" />
                    </p:confirmDialog>

                    <p:divider />

                </p:toolbarGroup>

                <p:divider />

                <p:toolbarGroup>
                    <p:menuButton value="#{ml.tr('Export')}">
                        <p:menuitem>
                            <h:commandLink>
                                <h:outputText value="Excel" />
                                <p:dataExporter type="xls" target="userList" 
                                                fileName="#{ml.tr('file_users')}"  />
                            </h:commandLink>
                        </p:menuitem>
                        <p:menuitem>
                            <h:commandLink>
                                <h:outputText value="PDF" />
                                <p:dataExporter type="pdf" target="userList" 
                                                fileName="#{ml.tr('file_users')}"
                                                encoding="utf8" />
                            </h:commandLink>
                        </p:menuitem>
                        <p:menuitem>
                            <h:commandLink>
                                <h:outputText value="Csv" />
                                <p:dataExporter type="csv" target="userList" 
                                                fileName="#{ml.tr('file_users')}" 
                                                excludeColumns="3,4" />
                            </h:commandLink>
                        </p:menuitem>
                        <p:menuitem>
                            <h:commandLink>
                                <h:outputText value="XML" />
                                <p:dataExporter type="xml" target="userList" 
                                                fileName="#{ml.tr('file_users')}" />
                            </h:commandLink>
                        </p:menuitem>
                    </p:menuButton>
                </p:toolbarGroup>

            </p:toolbar>
            <p:dataTable id="userList" var="user" value="#{secureMb.secure.users}"
                         paginator="true" rows="12"
                         selection="#{secureUserList.user}" selectionMode="single">

                <f:facet name="header">
                    "#{ml.tr('List of users')}"
                </f:facet>

                <p:column filterBy="#{user.username}"
                          headerText="#{ml.tr('Username')}"
                          filterMatchMode="contains">
                    <h:outputText value="#{user.username}" />
                </p:column>

                <p:column filterBy="#{user.firstname}"
                          headerText="#{ml.tr('Name')}"
                          filterMatchMode="contains">
                    <h:outputText value="#{user.firstname}" />
                </p:column>

                <p:column filterBy="#{user.lastname}"
                          sortBy="#{user.lastname}"
                          headerText="#{ml.tr('Surname')}"
                          filterMatchMode="contains">
                    <h:outputText value="#{user.lastname}" />
                </p:column>

                <p:column filterBy="#{user.email}"
                          headerText="#{ml.tr('Email')}"
                          filterMatchMode="contains">
                    <a href="mailto:#{user.email}">
                        <h:outputText value="#{user.email}" />
                    </a>
                </p:column>

                <p:column filterBy="#{user.phone}"
                          headerText="#{ml.tr('Phone')}"
                          filterMatchMode="contains">
                    <h:outputText value="#{user.phone}" />
                </p:column>

                <p:column filterBy="#{user.city}"
                          headerText="#{ml.tr('City')}"
                          filterMatchMode="contains">
                    <h:outputText value="#{user.city}" />
                </p:column>
            </p:dataTable>

            <h:commandLink>
                <p:graphicImage value="/images/excel.png" />
                <p:dataExporter type="dd" target="userList" fileName="cars" />
            </h:commandLink>

        </h:form>
    </ui:define>

</ui:composition>
